/*
 * @Author: yuqy
 * @Date: 2023-10-17 16:10:44
 * @LastEditors: yuqy
 * @LastEditTime: 2023-10-24 16:33:20
 * @Descripttion: -
 */
import route from '@/router'
import store from "@/store";
import util from '@/libs/util'
let VITE_APP_BASE_URL = import.meta.env.VITE_APP_BASE_URL;
/**
 * @name: 去听讲页面
 * @msg: 
 * @return {*}
 */
export const goListenSpeaker = (code, joinType = 1) => {
    const isWeb = store.getters.getAppIsWeb;
    route.push({ path: './listenSpeaker', query: { code, joinType } });
    if (isWeb) return
    // 需要给主进程发送指令变换窗口大小
    setTimeout(() => {
        window.electronAPI.resize("listenSpeaker", {})
    }, 1000)
}

/**
 * @name: 去主讲页面
 * @msg: 
 * @return {*}
 */
export const goHomeSpeaker = (code) => {
    const isWeb = store.getters.getAppIsWeb;
    if (isWeb) {
        return route.push({ path: './homeSpeaker', query: { code } });
    }
    let { homeWidth, clientHeight, wrapRight } = util.getWidthHeight();
    let width = homeWidth;
    let height = clientHeight;
    let right = wrapRight;
    // $("#home_wrap").hide()
    // $("#loading_wrap").show()
    // 需要给主进程发送指令变换窗口大小
    window.electronAPI.resize("homeSpeaker", { width, height, right });
    let url = `${window.location.origin}/${VITE_APP_BASE_URL}/home/homeSpeaker?code=${code}&joinType=${joinType}`;
    window.location.replace(`${url}`)
}

/**
 * @name: 获取观看的直播地址
 * @msg: 
 * @return {*}
 */
export const getLiveUrl = (code) => {
    let url = `${window.location.origin}/${VITE_APP_BASE_URL}/classlive?code=${code}`;
    return url
}

/**
 * @name: 主讲老师打开白板
 * @msg: 
 * @return {*}
 */
export const openWhiteBoard = (code) => {
    const isWeb = store.getters.getAppIsWeb;
    let URL = `${window.location.origin}/${VITE_APP_BASE_URL}/whiteboard?code=${code}`;
    if (isWeb) return window.open(URL)
    try {
        window.open(URL, 'whiteboard', 'primary=no,fullscreen=yes')
    } catch (error) {
        console.log(error)
    }
}

/**
 * @name: 打开个人中心
 * @msg: 
 * @return {*}
 */
export const goUsercenter = () => {
    const isWeb = store.getters.getAppIsWeb;
    let URL = `/${VITE_APP_BASE_URL}/person`
    if (isWeb) {
        return window.open(URL, 'person', 'primary=no,fullscreen=yes')
    }
    let width = util.getWidthHeight().personWidth
    let height = width / 418 * 386
    try {
        URL = `${window.location.origin}/${VITE_APP_BASE_URL}/person?width=${width}&height=${height}`;
        window.open(URL, 'person', 'primary=no,fullscreen=yes')
    } catch (error) {
        console.log(error)
    }
}

/**
 * @name: 打开副屏幕
 * @msg: 
 * @return {*}
 */
export const openAudience = (code) => {
    // const isWeb = store.getters.getAppIsWeb;
    // if (isWeb) return;
    let URL = `${window.location.origin}/${VITE_APP_BASE_URL}/audience?code=${code}`
    let windoWaudience = null
    try {
        windoWaudience = window.open(URL, 'audience', 'primary=no,fullscreen=yes')
    } catch (error) {

    }
    return windoWaudience
}

